import Vue from 'vue'
import App from './App.vue'
import router from './router'

// plug
import Loading from "./plug/loading"
Vue.use(Loading)

Vue.config.productionTip = false

Vue.prototype.goto = function([path, params = {}, query = {}]) {
  //路由跳转方法,vue2.0+
  if (!path) {
    throw new Error("the vm or the path can't be null")
  } else
    this.$router.push({
      name: path,
      params: params,
      query: query
    });
}

router.beforeEach((to, from, next) => {
  let loginToken = window.sessionStorage.getItem("loginToken");
  if (loginToken) {
    next();
  } else if (to.name == 'Login') {
    next();
  } else {
    next({
      name: 'Login'
    });
  }
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
